<?php

session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
$sql=" select * from ".DBQIAN."daogou order by province desc limit 0, 60000";
$result = mysql_query($sql);
/*导出csv格式文件*/
//$str = "手机号码,真实姓名,性别,省份,城市,详细地址,积分,注册时间,微信Openid\n";
//$str =  iconv('utf-8','gb2312',$str);//utf8转为gb2312//iconv('gb2312','utf-8',$str),csv只能导出gb2312格式；
//while($row=mysql_fetch_array($result)){
//$username = iconv('utf-8','gb2312',$row['username']);
//$name = iconv('utf-8','gb2312',$row['name']);
//$sex = iconv('utf-8','gb2312',$row['sex']);
//$province = iconv('utf-8','gb2312',$row['province']);
//$city = iconv('utf-8','gb2312',$row['city']);
//$address = iconv('utf-8','gb2312',$row['address']);
//$credit = iconv('utf-8','gb2312',$row['credit']);
//$create_time = iconv('utf-8','gb2312',$row['createtime']);
//$openid = iconv('utf-8','gb2312',$row['openid']);
//$str .= $username.",".$name.",".$sex.",".$province.",".$city.",".$address.",".$credit.",".$create_time.",".$openid."\n";
//}
//$filename = date('Ymd').'.csv';
//export_csv($filename,$str);
//function export_csv($filename,$data) {
//header("Content-type:text/csv");
//header("Content-Disposition:attachment;filename=".$filename);
//header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
//header('Expires:0');
//header('Pragma:public');
//echo $data;
//}

include 'excel/PHPExcel.php';
$phpexcel = new PHPExcel();
$phpexcel->getProperties()->setCreator('旭发防伪');
$phpexcel->getProperties()->setLastModifiedBy('旭发防伪');
$phpexcel->getProperties()->setTitle('导购信息表');
$phpexcel->getProperties()->setSubject('导购信息表');
$phpexcel->getProperties()->setDescription('导购信息表-旭发技术支持');
$phpexcel->getProperties()->setKeywords('导购信息表');
$phpexcel->getProperties()->setCategory('导购信息表');
$phpexcel->setActiveSheetIndex(0);
$phpexcel->getActiveSheet()->setTitle('导购信息表');
$phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(20); 
$phpexcel->getActiveSheet()->setCellValue('A1', '手机号码');
$phpexcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(25); 
$phpexcel->getActiveSheet()->setCellValue('B1', '真实姓名');
$phpexcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(10); 
$phpexcel->getActiveSheet()->setCellValue('C1', '性别');
$phpexcel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(20); 
$phpexcel->getActiveSheet()->setCellValue('D1', '省份');
$phpexcel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(20); 
$phpexcel->getActiveSheet()->setCellValue('E1', '城市');
$phpexcel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(20); 
$phpexcel->getActiveSheet()->setCellValue('F1', '门店名称');
$phpexcel->getActiveSheet()->getStyle('G1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth(50); 
$phpexcel->getActiveSheet()->setCellValue('G1', '门店店址');
$phpexcel->getActiveSheet()->getStyle('H1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth(10); 
$phpexcel->getActiveSheet()->setCellValue('H1', '职位');
$phpexcel->getActiveSheet()->getStyle('I1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('I')->setWidth(30); 
$phpexcel->getActiveSheet()->setCellValue('I1', '注册时间');
$phpexcel->getActiveSheet()->getStyle('J1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('J')->setWidth(30); 
$phpexcel->getActiveSheet()->setCellValue('J1', '微信名');
$phpexcel->getActiveSheet()->getStyle('K1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('K')->setWidth(30); 
$phpexcel->getActiveSheet()->setCellValue('K1', '微信openID');
$phpexcel->getActiveSheet()->getStyle('L1')->getFont()->setBold(true); 
$phpexcel->getActiveSheet()->getColumnDimension('L')->setWidth(10); 
$phpexcel->getActiveSheet()->setCellValue('L1', '是否审核');
$i = 2;
while($row=mysql_fetch_array($result))
{
	$phpexcel->getActiveSheet()->setCellValueExplicit('A' . $i, $row['username'], PHPExcel_Cell_DataType::TYPE_STRING);
	$phpexcel->getActiveSheet()->setCellValue('B' . $i, $row['name'], PHPExcel_Cell_DataType::TYPE_STRING);
	$phpexcel->getActiveSheet()->setCellValue('C' . $i, $row['sex']);
	$phpexcel->getActiveSheet()->setCellValue('D' . $i, $row['province']);
	$phpexcel->getActiveSheet()->setCellValue('E' . $i, $row['city']);
	$phpexcel->getActiveSheet()->setCellValue('F' . $i, $row['shopname'], PHPExcel_Cell_DataType::TYPE_STRING);
	$phpexcel->getActiveSheet()->setCellValue('G' . $i, $row['shopaddress'], PHPExcel_Cell_DataType::TYPE_STRING);
	if ($row['job']==1)
	{
		$phpexcel->getActiveSheet()->setCellValue('H' . $i, '老板', PHPExcel_Cell_DataType::TYPE_STRING);
	}
	else if ($row['job']==2)
	{
		$phpexcel->getActiveSheet()->setCellValue('H' . $i, '店长', PHPExcel_Cell_DataType::TYPE_STRING);
	}
	else if ($row['job']==3)
	{
		$phpexcel->getActiveSheet()->setCellValue('H' . $i, '导购', PHPExcel_Cell_DataType::TYPE_STRING);	
	}
	else 
	{
		$phpexcel->getActiveSheet()->setCellValue('H' . $i, '其他', PHPExcel_Cell_DataType::TYPE_STRING);
	}
	$phpexcel->getActiveSheet()->setCellValue('I' . $i, $row['create_time'], PHPExcel_Cell_DataType::TYPE_STRING);
	$phpexcel->getActiveSheet()->setCellValue('J' . $i, $row['wx_user'], PHPExcel_Cell_DataType::TYPE_STRING);
	$phpexcel->getActiveSheet()->setCellValue('K' . $i, $row['wx_openid'], PHPExcel_Cell_DataType::TYPE_STRING);
	if ($row['status'] == 1)
	{
		$phpexcel->getActiveSheet()->setCellValue('L' . $i, '已审核', PHPExcel_Cell_DataType::TYPE_STRING);
	}
	else 
	{
		$phpexcel->getActiveSheet()->setCellValue('L' . $i, '未审核', PHPExcel_Cell_DataType::TYPE_STRING);
	}
	++$i;
}
$outputFileName = "导购信息表.xls";
$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
header("Content-Type: application/vnd.ms-excel");
header("Content-type: application/octet-stream");
header("Content-type: application/download");
header('Content-Disposition:inline;filename="' . $outputFileName . '"');
header("Content-Transfer-Encoding:binary");
header("Cache-Control: must-revalidate, post-check=0, pri-check=0");
header("Pragma: no-cache");
$objWriter->Save('php://output');
exit;
?>